import 'package:flutter/widgets.dart';

// 用于创建没有子节点的渲染对象
class CustomCircle extends LeafRenderObjectWidget {
  final Color color;
  final double radius;
  
  const CustomCircle({
    super.key,
    required this.color,
    required this.radius,
  });
  
  @override
  RenderObject createRenderObject(BuildContext context) {
    return RenderCustomCircle(
      color: color,
      radius: radius,
    );
  }
  
  @override
  void updateRenderObject(BuildContext context, RenderCustomCircle renderObject) {
    renderObject
      ..color = color
      ..radius = radius;
  }
}

// 对应的 RenderObject
class RenderCustomCircle extends RenderBox {
  Color _color;
  double _radius;
  
  RenderCustomCircle({
    required Color color,
    required double radius,
  }) : _color = color, _radius = radius;
  
  set color(Color value) {
    if (_color != value) {
      _color = value;
      markNeedsPaint();
    }
  }
  
  set radius(double value) {
    if (_radius != value) {
      _radius = value;
      markNeedsLayout();
    }
  }
  
  @override
  void performLayout() {
    size = Size(_radius * 2, _radius * 2);
  }
  
  @override
  void paint(PaintingContext context, Offset offset) {
    final canvas = context.canvas;
    final paint = Paint()..color = _color;
    canvas.drawCircle(
      offset + Offset(_radius, _radius),
      _radius,
      paint,
    );
  }
}